<?php
class ext_tender_model extends MY_Model {
	var $model = 'ext_tender';
	
	function GetJSON()
	{
		$ls_sql =" SELECT * FROM EXT_TENDER
				   WHERE 	(UPPER(kode_tender) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tender) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(app_id) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'KODE_TENDER' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('ext_tender', $arr_data);
		
		$this->AuditTrail(	'ext_tender',// Table
							'Create',		// Action
							''				// Primary Key
							);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('ext_tender', $arr_data, $arr_rule);
		
		$this->AuditTrail(	'ext_tender',		// Table
							'Update',				// Action
							json_encode($arr_rule)	// Primary Key
							);
	}
	
	function GetSingle($as_kode_tender){
		$result = $this->db->get_where('ext_tender', array('ref_key' => $as_kode_tender));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_tender)
	{
		$ls_sql =" SELECT * FROM EXT_TENDER";

		$result	= $this->db->query("SELECT * FROM EXT_TENDER WHERE KODE_TENDER = '".$as_kode_tender."'");
		
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			$this->db->delete('ext_tender', $arr_rule);
			
			$this->AuditTrail(	'ext_tender',		// Table
								'Delete',				// Action
								json_encode($arr_rule)	// Primary Key
								);
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>